{include file="public/header" /}

<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/admin/index/welcome">首页</a>

            <a href="">评论</a>
            <a>
              <cite>{:get_zd_name("title",'news',"id=$uid")}</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="q"  placeholder="请输入标题" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>

                </div>
                <form action="/admin/roomcomment/action" method="post" id="contentForm" name="formlist" class="layui-form" onkeydown="if(event.keyCode==13) return false;">
                    <div class="layui-card-header">
<!--                        <button type="submit" name="act" value="alldel" onClick="return checkData();" class="layui-btn layui-btn-danger"><i class="layui-icon"></i>批量删除</button>-->

                        <div class="fenye">条数
                            <select>
                                <option value="10" {if condition="$pagesizes eq 10"}selected {/if}}>10</option>
                                <option value="20" {if condition="$pagesizes eq 20"}selected {/if}}>20</option>
                                <option value="50" {if condition="$pagesizes eq 50"}selected {/if}}>50</option>
                                <option value="100" {if condition="$pagesizes eq 100"}selected {/if}}>100</option>
                            </select>
                        </div>
                    </div>
                    <style>
                        .fenye{
                            width: 120px;
                            float: right;
                        }
                        .fenye .layui-unselect{
                            float: right;
                            width: 80px;
                        }
                    </style>


                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                                </th>
                                <th>ID</th>
                                <th>标题</th>
                                <th>排序</th>
                                <th>时间</th>
                                <th> 状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="v"}

                                <tr>
                                    <td>
                                        <input type="checkbox" class="checkid" checkid="{$v.id}" name="checkid[]" value="{$v.id}"   lay-skin="primary">
                                    </td>
                                    <td>{$v.id}</td>
                                    <td >{$v.title}</td>

                                    <td>
                                        {:date("Y-m-d",$v.sendtime)}
                                    </td>
                                    <td>
                                        <input type="checkbox" name="status"   lay-text="开启|停用" {if condition="$v['status'] eq 1"}checked {/if} lay-skin="switch">
                                    </td>

                                    <td class="td-manage">
                                        <a title="编辑" href="/admin/comment/add/id/{$v.id}" class="ml-5" style="text-decoration:none">
                                            <i class="layui-icon">&#xe642;</i>
                                        </a>
                                        <a title="删除" href="javascript:;" onclick="del({$v.id})" style="text-decoration:none">
                                            <i class="layui-icon">&#xe640;</i>
                                        </a>
                                    </td>
                                </tr>
                            {/volist}
                            </tbody>
                        </table>

                    </div>
                </form>

                <div class="layui-card-body ">
                    <div class="page">
                      {$list->render()}

                    </div>
                </div>


            </div>
        </div>
    </div>
</div>
</body>
<script>

    window.onload=function(){

        $(".layui-anim dd").click(function () {
            pagesize=$(this).attr("lay-value");
            // alert(pagesize);
            window.location.href="?pagesize="+pagesize;
            // location.reload("?11");
        })

        $(".layui-form-switch").click(function () {
            id=$(this).parent().parent().find("td").next("td").html();
            zd=$(this).prev().attr("name");
            var jsonData = {
                "id": id,
                "zd": zd,


            };
            $.ajax({
                type: "POST",
                url: "/admin/comment/audit",
                data: jsonData,
                dataType: "json",
                success: function(data){
                    if(data.status==0){
                        // alert(data.msg);
                        layer.msg(data.msg);
                    }else{
                        layer.msg(data.msg);
                        return false;
                    }
                },
                error:function(data) {
                    alert(data.msg);
                }
            });
        })


    }


    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody .checkid').prop('checked',true);
            }else{
                $('tbody .checkid').prop('checked',false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


    });


    /*删除*/
    function del(id){

        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            // $(obj).parents("tr").remove();
            window.location.href="/admin/comment/del/id/"+id;
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }



    function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</html>